<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>用户注册</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="网站关键词">
<meta name="Description" content="网站介绍">
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/iconfont.css">
<link rel="stylesheet" href="./css/reg.css">
</head>
<body>
<span style="display: none;" class="span1"></span>
	<div id="ajax-hook"></div>
	<div class="wrap">
		<div class="wpn">
			<div class="form-data pos">
				<a href=""><img src="./img/logo.png" class="head-logo"></a>
				<!--<p class="tel-warn hide"><i class="icon-warn"></i></p>-->
				<form>
					<p class="p-input pos">
						<label for="tel">手机号</label> <input type="number" id="tel"
							autocomplete="off" > <span class="tel-warn tel-err hide">
							<em ></em><i
							class="icon-warn"></i></span>
					</p>
					<p class="p-input pos" id="pwd">
						<label for="passport">输入密码</label> <input type="password"
							style="display: none" /> <input type="password" id="passport">
						<span class="tel-warn pwd-err hide"><em></em><i
							class="icon-warn" style="margin-left: 5px"></i></span>
					</p>
					<p class="p-input pos " id="confirmpwd">
						<label for="passport2">确认密码</label> <input type="password"
							style="position: absolute; top: -998px" /> <input type="password"
							id="passport2"> <span
							class="tel-warn confirmpwd-err hide"><em></em><i
							class="icon-warn" style="margin-left: 5px"></i></span>
					</p>
					
				</form>
				<button class="lang-btn" >注册</button>
				<div class="bottom-info">
					已有账号，<a href="/login">马上登录</a>
				</div>
				<p class="right">Powered by © 2019</p>
			</div>
		</div>
	</div>
	<script src="./js/jquery.js"></script>
	<script src="./js/agree.js"></script>
	<!-- <script src="./js/reg.js"></script> -->
	<script type="text/javascript">
		$(function() {
			//点击注册
			$(".lang-btn").click(function() {
				var $pwd = $("#passport").val().trim();
				var $pwd2 = $("#passport2").val().trim();
				var $tel= $("#tel").val().trim();
				if($pwd==""||$pwd2==""){
					alert("密码不能为空！！");
					return false;
				}else if($pwd!=$pwd2){
					alert("密码不相等！");
					return false;
				}else if($(".span1").text()=="false"){
					alert("该号码已被注册");
					return false;
				}
				
				var data = "userphone="+$tel+"&userpassword="+$pwd;
				$.ajax({
					type:"POST",
					dataType:"text",
					url:"/user_reg_saves",
					data:{"userphone":$tel,"userpassword":$pwd},
					success:function(data){
						if(data=="success"){
							alert("注册成功");
							location.href= "/login";
						}else if(data=="error"){
							alert("注册失败");
						}
					},
					error:function(XMLHttpRequest, textStatus, errorThrown){
						 alert(XMLHttpRequest.status); 
						 alert(XMLHttpRequest.readyState); 
						 alert(textStatus);
					}
				})
			});
			$("#tel").blur(function() {
				var $tel= $("#tel").val().trim();
				var data = "userphone="+$tel;
				if($tel==""){
					alert("请输入电话号！");
					return false;
				}
				/* //设置手机格式
				var tal = /^1[357]\d{9}$/;
				if(!tal.test($tel)){
					alert("手机号码格式不正确！");
					$(".span1").text("false");
					return false;
				}else{
					$(".span1").text("");
				} */
				
				if($tel!=""){
					$.ajax({
						type:'POST',
						dataType:"json",
						url:'/reg_phone_repeat',
						data:data,
						success:function(data){//返回json结果
							if(data.data=="false"){
								alert("该号码已被注册");
								$(".span1").text("false");
							}else{
								$(".span1").text("");
							}
						},
						error:function(data){
					        //请求出错处理
					        alert("出现异常");
					        $(".span1").text("false");
				   	 	}
					})
				}
			})
			//密码格式
		/* 	$("#passport").blur(function() {
				var $pwd = $("#passport").val().trim();
				var pwd =/^[A-Za-z0-9]{6,8}$/;
				if(!pwd.test($pwd)){
					alert("请输入6-8个英文单词或者数字的密码！");
					$(".span1").text("false");
					return false;
				}else{
					$(".span1").text("");
				}
			}) */
		})
	</script>
	<div style="text-align: center;">
		<p>
			更多模板：<a href="http://www.mycodes.net/" target="_blank">源码之家</a>
		</p>
	</div>
</body>
</html>